<?php

?>

<div class="panel">
    <div class="panel-heading">订单信息</div>
    <div class="panel-body">
        <div class="form-horizontal">
            <div class="form-group">
                <label class="col-sm-2 form-label-key">订单编号:</label>
                <label class="col-sm-4 form-label-value"><?= $item['order_code'] ?></label>
                <label class="col-sm-2 form-label-key">所属机构:</label>
                <label class="col-sm-4 form-label-value"><?= $item['institution_name'] ?></label>
            </div>
            <div class="form-group">
                <label class="col-sm-2 form-label-key">订单销售总金额:</label>
                <label class="col-sm-4 form-label-value">￥<?= $item['total_selling_price'] ?></label>
                <label class="col-sm-2 form-label-key">订单结算总金额:</label>
                <label class="col-sm-4 form-label-value">￥<?= $item['total_settlement_price'] ?></label>
            </div>
            <div class="form-group">
                <label class="col-sm-2 form-label-key">下单用户:</label>
                <label class="col-sm-4 form-label-value"><?= $item['user_name'] ?></label>
                <label class="col-sm-2 form-label-key">订单状态:</label>
                <label class="col-sm-4 form-label-value">
                    <?= $item['status_name'] ?>
                    <?php
                    switch ($item['status']) {
                        case 10:  // 待审核订单
                            echo " <a class=' btn btn-primary' id='btnApproveOrderFlow' data-id='{$item['id']}' data-code='{$item['order_code']}'>订单审核</a>";
                            break;
                        case 11:  // 待结算订单
                        case 12:  // 未结算订单
                            echo " <a class=' btn btn-primary' id='btnPayOrderFlow' data-id='{$item['id']}' data-code='{$item['order_code']}'>订单结算</a>";
                            break;
                        case 13:  // 支付成功订单
                            echo " <a class=' btn btn-primary' id='btnAddOrderFlow' data-id='{$item['id']}' data-code='{$item['order_code']}'>订单提交</a>";
                            break;
                    }
                    ?>
                </label>
            </div>
            <div class="form-group">
                <label class="col-sm-2 form-label-key">下单时间:</label>
                <label class="col-sm-4 form-label-value"><?= $item['create_datetime'] ?></label>
            </div>
            <div class="form-group">
                <label class="col-sm-2 form-label-key">备注:</label>
                <label class="col-sm-10 form-label-value"><?= $item['remark'] ?></label>
            </div>
        </div>
    </div>
</div>
<div class="panel">
    <div class="panel-heading">商品信息</div>
    <div class="panel-body">
        <div class="table-responsive">
            <table class="table table-bordered table-hover table-condensed">
                <thead class="nowrap">
                <tr>
                    <th>商品编号</th>
                    <th>商品名称</th>
                    <th>是否跨境</th>
                    <th>销售价格</th>
                    <th>结算价格</th>
                    <th>购买数量</th>
                </tr>
                </thead>
                <tbody>
                <?php
                foreach ($item['goods_list'] as $goodsItem) {
                    ?>
                    <tr>
                        <td><?= $goodsItem['goods_code'] ?></td>
                        <td><?= $goodsItem['goods_name'] ?></td>
                        <td><?= $goodsItem['is_crossborder'] == 1 ? '是' : '否' ?></td>
                        <td><?= $goodsItem['selling_price'] ?></td>
                        <td><?= $goodsItem['settlement_price'] ?></td>
                        <td> <?= $goodsItem['quantity'] ?></td>
                    </tr>
                    <?php
                }
                ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?php
if (count($backGoodsItems) > 0) {
    ?>
    <div class="panel">
        <div class="panel-heading">退货信息</div>
        <div class="panel-body">
            <div class="table-responsive">
                <table class="table table-bordered table-hover table-condensed">
                    <thead class="nowrap">
                    <tr>
                        <th>机构名称</th>
                        <th>商品编号</th>
                        <th>商品名称</th>
                        <th>结算价格</th>
                        <th>退货数量</th>
                        <th>退货金额</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php
                    foreach ($backGoodsItems as $goodsItem) {
                        ?>
                        <tr>
                            <td><?= $goodsItem['institution_name'] ?></td>
                            <td><?= $goodsItem['goods_code'] ?></td>
                            <td><?= $goodsItem['goods_name'] ?></td>
                            <td><?= $goodsItem['settlement_price'] ?></td>
                            <td> <?= $goodsItem['quantity'] ?></td>
                            <td> <?= $goodsItem['settlement_price'] * $goodsItem['quantity'] ?></td>
                        </tr>
                        <?php
                    }
                    ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <?php
}
?>

<script type="application/javascript">
    $(function () {
        $('#btnApproveOrderFlow').click(function () {
            var data = {};
            data.order_flow_id = $(this).attr('data-id');
            data.order_code = $(this).attr('data-code');
            requestJson('approve-order-flow-handler', data, true, function (responseData) {
                loadOrderFlowDetailPartial(data.order_flow_id);
            }, function (responseData) {
                loadOrderFlowDetailPartial(data.order_flow_id);
            });
        });

        $('#btnPayOrderFlow').click(function () {
            var data = {};
            data.order_flow_id = $(this).attr('data-id');
            data.order_code = $(this).attr('data-code');
            requestJson('pay-order-flow-handler', data, true, function (responseData) {
                if (responseData.status != '0') {
                    alert(responseData.message);
                }
                loadOrderFlowDetailPartial(data.order_flow_id);
            }, function (responseData) {
                loadOrderFlowDetailPartial(data.order_flow_id);
            });
        });

        $('#btnAddOrderFlow').click(function () {
            var data = {};
            data.order_flow_id = $(this).attr('data-id');
            data.order_code = $(this).attr('data-code');
            requestJson('add-order-flow-handler', data, true, function (responseData) {
                if (responseData.status != '0') {
                    alert(responseData.message);
                }
                loadOrderFlowDetailPartial(data.order_flow_id);
            }, function (responseData) {
                loadOrderFlowDetailPartial(data.order_flow_id);
            });
        });
    });
</script>